/**
 * 👨‍💻 伟谭
 * 📅 2017/11/25
 */

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

#pragma mark - Class method

#pragma mark - Life cycle


- (void)viewDidLoad {
    self.navigationController.navigationBar.hidden = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    [self setupNavigation];
}

#pragma mark - Override
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}

#pragma mark - Event response

#pragma mark - Protocol

#pragma mark <<#XXXDelegate#>>

#pragma mark - Public method

#pragma mark - Private method
- (void)setupNavigation {
    
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *image = IMG(@"返回");
    backButton.frame = CGRectMake(0, 0, image.size.width, image.size.height);
    [backButton setImage:image forState:UIControlStateNormal];
    [backButton addTarget:self
                   action:@selector(back)
         forControlEvents:UIControlEventTouchUpInside];
    [backButton setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:backButton];
    [self.navigationItem setLeftBarButtonItem:item];
    
    UINavigationBar *bar = self.navigationController.navigationBar;
    [bar setBarTintColor:NavColor];
    [self removeBottomLineInNavigation];
    if(iOS7_OR_LATER) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.extendedLayoutIncludesOpaqueBars = NO;
        self.modalPresentationCapturesStatusBarAppearance = NO;
        /*
         CGRect statusBarViewFrame = CGRectMake(0, -20, self.view.frameWidth, 20);
         UIView *statusBarView = [[UIView alloc] initWithFrame:statusBarViewFrame];
         statusBarView.backgroundColor=[UIColor whiteColor];
         [self.navigationController.navigationBar addSubview:statusBarView];
         */
        self.navigationController.navigationBar.translucent = NO;
    }
}

// 移除UINavigationBar底部的黑线
- (void)removeBottomLineInNavigation {
    NSArray *subViews = [self.navigationController.navigationBar subviews];
    if ([subViews count] > 0) {
        UIView *view = subViews[0];
        NSArray *ssbviews = [view subviews];
        NSInteger count = [ssbviews count];
        if (count > 0) {
            for (NSInteger i=0; i<count; i++) {
                UIView *ssbView = ssbviews[i];
                if ([ssbView isKindOfClass:[UIImageView class]]) {
                    [ssbView removeFromSuperview];
                }
            }
        }
    }
}

-(void)setTitle:(NSString *)title {
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0.0f, 0.0f , 100.0f, 44.0f)];
    titleLabel.backgroundColor = [UIColor clearColor];  //设置Label背景透明
    titleLabel.font = [UIFont systemFontOfSize:17];  //设置文本字体与大小
    //titleLabel.textColor = [UIColor blackColor];  //设置文本颜色
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = title;  //设置标题
    self.navigationItem.titleView = titleLabel;
    
}

- (void)back {
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark - Getter & Setter

@end
